<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>时钟</title>
		<script>
			function showTime(){
				document.getElementById("timer").innerHTML=new Date().toLocaleString();
			}
			window.onload=function(){
				showTime();
			}
			// window.setInterval("showTime()",1000);
			var timer=window.setInterval(function(){
				showTime();
				//document.getElementById("timer").innerHTML=new Date().toLocaleString();
			},1000);
			
			function stopTime(){
				window.clearInterval(timer);
			}
		</script>
	</head>
	<body>
		<div id="timer"></div>
		<button type="button" onclick="stopTime()">时间停止</button>
	</body>
</html>